package com.heima.behavior.controller.v1;

import com.heima.behavior.service.LikesBehaviorService;
import com.heima.common.redis.CacheService;
import com.heima.model.behavior.dtos.LikesBehaviorDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处理用户 点赞 行为Controller: 点赞、阅读、不喜欢
 */
@Slf4j
@RestController
@RequestMapping("/api/v1")
public class LikesBehaviorController {
    @Autowired
    private LikesBehaviorService likesBehaviorService;

    @GetMapping("/ping")
    public String pingtest() {
        return "From app-gateway To leadnews-behavior is ok...";
    }

    /**
     * 用户对某篇文章进行点赞
     * 入参: {"equipmentId":"88888888","articleId":"1671406228129058800","type":0,"operation":0}
     * operation: 0 点赞   1 取消点赞
     * @param dto
     * @return
     */
    @PostMapping("/likes_behavior")
    public ResponseResult likes(@RequestBody LikesBehaviorDto dto) {
        log.info("用户对文章进行点赞或取消点赞,入参:{}", dto);

        //调用servcie
        return likesBehaviorService.like(dto);
    }
}
